package com.briup.smartcity_group7.config;

import com.briup.smartcity_group7.web.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: lenovo
 * @Date: 2023/01/02/12:55
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(new JwtInterceptor()).addPathPatterns("/auth/**");
    }

    //添加跨域资源共享的映射规则
    public void addCorsMappings(CorsRegistry registry){
        //设置所有的前端访问路径的跨域规则：所有客户端(前端) 请求方式5种 请求头任意 不携带cookie 保存时间
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(false)
                .maxAge(3000);
    }
}
